﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class UserDAL : BaseDAL
    {
        public DataTable GetAllData(string tableName = "Tmp")
        {
            try
            {
                Open();
                Cmd.CommandText = @"select * from tb_user";
                var res = Cmd.ExecuteReader();
                var tb = new DataTable(tableName);
                tb.Load(res);
                Close();
                return tb;
            }
            catch { return null; }
        }

        public bool Insert(string id, string pass, int role)
        {
            try
            {
                Open();

                Cmd.CommandText =
                    string.Format("insert into tb_user(id, pass, role) values({0},{1},{2})",
                    id, pass, role);

                Cmd.ExecuteNonQuery();
                Close();
                return true;
            }
            catch { return false; }
        }
    }
}